using MultiAgentsShared;
using static MultiAgentsClient.Manager.MessageManager;
using static MultiAgentsClient.Manager.ProjectManager;

namespace MultiAgentsClient.Presentation.Component;

public sealed partial class HeaderPanel : UserControl
{
    private readonly IEventBus eventBus;

    public static readonly DependencyProperty MainViewModelProperty =
        DependencyProperty.Register("MainViewModel", typeof(MainPageModel), typeof(HeaderPanel), new PropertyMetadata(null));

    public MainPageModel MainPageModel
    {
        get { return (MainPageModel)GetValue(MainViewModelProperty); }
        set { SetValue(MainViewModelProperty, value); }
    }

    public HeaderPanel()
    {
        InitializeComponent();

        DataContext = new BindableHeaderPanelModel();
        eventBus = EventBus.Instance;
    }

    private void LLMModelSelectionChanged(object _, SelectionChangedEventArgs e)
    {
        var dataContext = (BindableHeaderPanelModel)DataContext;

        string? model = dataContext.SelectedLLMModel;
        if (string.IsNullOrEmpty(model))
        {
            return;
        }

        eventBus.Publish(new LLMModelSelectionChangedCommand(model));
    }

    private void AllowToolCallToggle_Toggled(object sender, RoutedEventArgs e)
    {
        var toggleSwitch = sender as ToggleSwitch ?? throw Debug.ShouldNotHappen();

        bool isOn = toggleSwitch.IsOn;

        eventBus.Publish(new AllowToolCallChangedCommand(isOn));
    }
}
